package com.luoxiang.socialandroid.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.bean.Exchange;
import com.luoxiang.socialandroid.bean.Recharge;

import java.util.List;

/**
 * @Description TODO
 * @systemUser Administrator
 * @Author LX
 * @Date 09-22-2022 周四 16:14
 */
public class SendCoinAdapter extends RecyclerView.Adapter<SendCoinAdapter.ViewHolder> {
    private View view;
    private List<Exchange> list;

    public SendCoinAdapter(List<Exchange> list) {
        this.list = list;
    }

    public static interface OnAddClickListener {
        // true add; false cancel
        public void onItemClicks(int position, int packageId); //传递boolean类型数据给activity
    }

    SendCoinAdapter.OnAddClickListener onItemAddClick;

    public void setOnAddClickListener(SendCoinAdapter.OnAddClickListener onItemAddClick) {
        this.onItemAddClick = onItemAddClick;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_sendcoin, parent, false);
        SendCoinAdapter.ViewHolder holder = new SendCoinAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.entercionnum.setText(holder.entercionnum.getContext().getString(R.string.mi_duihuan) + list.get(position).getCoin() + holder.entercionnum.getContext().getString(R.string.mi_jinbi));
        holder.btn_jifencount.setText(list.get(position).getCredit() + holder.entercionnum.getContext().getString(R.string.mi_jifen));
        holder.btn_jifencount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemAddClick.onItemClicks(position, list.get(position).getId());
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView entercionnum;
        Button btn_jifencount;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            entercionnum = itemView.findViewById(R.id.entercionnum);
            btn_jifencount = itemView.findViewById(R.id.btn_jifencount);
        }
    }
}
